<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建固定资产</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-first">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">资产编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>资产类别</label>
                        <div class="layui-input-block">
                            <div id="assettype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>资产名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">品牌</label>
                        <div class="layui-input-block">
                            <input type="text" name="pin" id="pin" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>规格型号</label>
                        <div class="layui-input-block">
                            <input type="text" name="gui" id="gui" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">出厂编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="chunum" id="chunum" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">采购日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="caidt" id="caidt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">采购金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" placeholder="请输入" autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">采购人</label>
                        <div class="layui-input-block">
                            <input type="text" name="caier" id="caier" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">质保期至</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhidt" id="zhidt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">售后联系方式</label>
                        <div class="layui-input-block">
                            <input type="text" name="shoutel" id="shoutel" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>管理部门</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=deptid&type=dept','770px','490px');"></div>
                                <div class="tanxiannei" id="deptid"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=deptid&type=dept','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="deptid_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">存放位置</label>
                        <div class="layui-input-block">
                            <input type="text" name="cunaddr" id="cunaddr" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div id="upload_files">
                    <?php include '../public/upinfo.php'?>
                </div>
            </div>
        </div>
    </div>
</form>
<script>


    $("#commentForm").validate({
        rules: {
            name: {required: true},
            gui: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            gui: {required: "请输入"},
        }
    });


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_asset_add}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;


                xmselect_dan('assettype', res.data.assettype, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#assettype").find('xm-select').removeClass('error');
                    }else{
                        $("#assettype").find('xm-select').addClass('error');
                    }
                });

                public_upload_file_load('upload_files');
                render_date();
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();

            if(!data.field.assettype){
                $("#assettype").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#assettype").find('xm-select').removeClass('error');
            }

            data.field.deptid = tan_tags_getvalue("#deptid", 'dept');
            if(!data.field.deptid){
                $("#deptid").parents('.tanxian').addClass('tanerror');
                $('#deptid_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#deptid").parents('.tanxian').removeClass('tanerror');
                $('#deptid_tanerror').text('');
            }

            if(!validRes){return false;}





            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_asset_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });


</script>
</body>
</html>
